package com.sk.bilibili.view.fragment.main.home;

import com.sk.bilibili.adapter.pager.main.ShopFragmentAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.shop.TipAdapter;
import com.sk.bilibili.adapter.vlayout.main.home.shop.TypeAdapter;
import com.sk.bilibili.bean.Member;
import com.sk.bilibili.databinding.FragmentMainShopBinding;
import com.sk.bilibili.event.MainMenuEvent;
import com.sk.bilibili.model.fragment.main.home.ShopModel;
import com.sk.bilibili.utils.DataUtils;
import com.sk.bilibili.view.activity.SearchActivity;
import com.sk.bilibili.view.fragment.BaseFragment;

import org.greenrobot.eventbus.EventBus;

public class ShopFragment extends BaseFragment<FragmentMainShopBinding, ShopModel> {

    @Override
    protected void afterSetView() {
        initHeader();
        initBody();
    }

    private void initHeader() {
        model.loadMember();
        bind.avAvatar.setOnClickListener(v -> EventBus.getDefault().post(MainMenuEvent.closeEvent()));
    }

    private void initBody() {
        bind.cgvType.setAdapter(new TypeAdapter(getContext(),this));
        bind.gvTip.setAdapter(new TipAdapter(getContext(),this));
        bind.vpShow.setAdapter(new ShopFragmentAdapter(getChildFragmentManager()));
        bind.tlShow.setupWithViewPager(bind.vpShow);
    }

    public void onTypeClick(int position) {
        toast("Type:"+position);
    }

    public void onTipClick(int position) {
        toast("Tip:"+position);
    }

    public void loadMemberSuccess(Member member) {
        bind.avAvatar.setRes(member.getAvatar(),member.getExtra().getPendant());
    }

}